

#include <stdio.h>
#include <stdlib.h>

#include <unistd.h> // for getopt.

#include "terminator.h"

static void usage(const char * exename)
{
    printf("usage: %s [-h] [-s | -r] [-d dictionary] [-c wordcount] [-i ignoreTable] cipherText\n", exename);
}

int main(int argc, char* argv[])
{
    int opt;
    Terminator  t;

    while ((opt = getopt(argc, argv, "hsrd:c:i:")) != -1) {
        switch (opt) {
        case 's':
            t.setWorkMode(Terminator::WORKMODE_SIMPLE);
            break;
        case 'r':
            t.setWorkMode(Terminator::WORKMODE_REPLACE);
            break;
        case 'd':
            t.setDictionary(optarg);
            break;
        case 'c':
            t.setWordCount(atoi(optarg));
            break;
        case 'i':
            t.setIgnoreTable(optarg);
            break;
        case 'h':
        case '?':
        default:
            usage(argv[0]);
            return -1;
        }
    }
    if (optind >= argc) {
        usage(argv[0]);
        return -1;
    }
    t.start(std::string(argv[optind]));

    return 0;
}

